package com.jiangong.service.impl;

import com.jiangong.Crawler.WeatherCrawler;
import com.jiangong.dao.InformationOverviewDao;
import com.jiangong.entity.*;
import com.jiangong.service.InformationOverviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;
@Service
public class InformationOverviewSerivceImpl implements  InformationOverviewService{
    @Autowired
    private InformationOverviewDao informationOverviewDao;

    @Override
    public List<Weather> Weather(Weather weather) {
        return informationOverviewDao.Weather(weather);
    }
//    @Override
//    public Double TotalPowerGeneration(Double totalpower) {
//        totalpower=informationOverviewDao.TotalPowerGeneration(totalpower);
//        return totalpower ;
//    }
    @Override
    public List<HPowerOut> HPowerOut(HPowerOut hPowerOut) {
        return informationOverviewDao.HPowerOut(hPowerOut);
    }
    @Override
    public List<TPowerOut> TPowerOut(TPowerOut tPowerOut) {
        return informationOverviewDao.TPowerOut(tPowerOut);
    }
    @Override
    public List<TPowerOutSum> TPowerOutSum(TPowerOutSum tPowerOutSum) {
        //        List<TotalPowerGeneration> result = new ArrayList<>();
//        Double power=TotalPowerGeneration(totalpower);

//        result.add(new TotalPowerGeneration(power,money,CO2,tree));
//        return result;
        List<TPowerOutSum> powerlist =  informationOverviewDao.TPowerOutSum(tPowerOutSum);
        double power = powerlist.get(0).getTotalpower();
        Double tree=power*0.0061 ;//相当于种树(冷杉)
        Double CO2=power*0.667*0.001;//累计碳排放（T）
        Double money=power*0.55;//累计收益(yuan)
        powerlist.get(0).setTree(tree);
        powerlist.get(0).setMoney(money);
        powerlist.get(0).setCo2(CO2);
        return powerlist;
    }

    @Override
    public List<PowerBarry> PowerBarry(PowerBarry powerBarry) {
        return informationOverviewDao.PowerBarry(powerBarry);
    }

    @Override
    public List<HPowerin> HPowerin(HPowerin hPowerin) {
        return informationOverviewDao.HPowerin(hPowerin);
    }
    @Override
    public List<TPowerin> TPowerin(TPowerin tpowerin) {
        return informationOverviewDao.TPowerin(tpowerin);
    }
    @Override
    public WeatherAPI weatherApi() throws IOException {
        WeatherAPI weather = WeatherCrawler.getWeather();
        informationOverviewDao.insertWeather(weather);
        System.out.println(weather);
        return weather;
    }
}

